package com.example.secondhandsysapi.Controller;

import com.example.secondhandsysapi.Entity.LookLogInfo;
import com.example.secondhandsysapi.Service.LookLogInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping(value = "look")
public class LookLogInfoController {
    @Autowired
    private LookLogInfoService lookLogInfoService;

    @GetMapping("del/{look_id}")
    private Integer delLookInfo(@PathVariable Integer look_id) {
        return lookLogInfoService.deleteByLookId(look_id);
    }


   @GetMapping("/querylook")
        public List<LookLogInfo> queryLookLogInfoThree(@RequestParam(required = false)Integer user_id,@RequestParam(required = false)String log_page,@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date log_time) {
       if (user_id != null && log_time != null && log_page!=null) {
           return lookLogInfoService.getAllLookLogInfoByUserIdTimePage(user_id,log_time,log_page);
       } else if (user_id==null&&log_page!=null&&log_time!=null) {
           return lookLogInfoService.getAllLookLogInfoByTimePage(log_time,log_page);
       } else if (user_id==null&&log_page==null&&log_time!=null) {
           return lookLogInfoService.getAllLookLogInfoByTime(log_time);
       } else if (user_id==null&&log_page!=null&&log_time==null) {
           return lookLogInfoService.getAllLookLogInfoByPage(log_page);
       } else if (user_id!=null&&log_time==null&&log_page==null) {
           return lookLogInfoService.getAllLookLogInfoByUserId(user_id);
       } else if (user_id!=null&&log_time!=null&&log_page==null) {
           return lookLogInfoService.getAllLookLogInfoByUserIdTime(user_id,log_time);
       }else if (user_id==null&&log_page==null&&log_time==null) {
           return lookLogInfoService.getAllLookLogInfoAll();
       }else {
           return lookLogInfoService.getAllLookLogInfoByUserIdPage(user_id,log_page);
       }
   }
}
